﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using p_Library;

namespace LIM
{
	class cls_Registry
	{
        static string _path = @"3PSolutions\LIMS\";
        public static void Save_DatabaseConnectionString(string str)
        {
            cls_CONCryptography cls_CONCryptography = new cls_CONCryptography();

            RegistryKey _keyReg = Registry.CurrentUser.CreateSubKey(_path);
            _keyReg.SetValue("DatabaseConnectionString", cls_CONCryptography.mtd_Encrypt(str));
        }
        public static string Get_DatabaseConnectionString()
        {
            cls_CONCryptography cls_CONCryptography = new cls_CONCryptography();

            RegistryKey _keyReg = Registry.CurrentUser.CreateSubKey(_path);
            return _keyReg.GetValue("DatabaseConnectionString") == null ? "" : cls_CONCryptography.mtd_Decrypt(_keyReg.GetValue("DatabaseConnectionString").ToString());
        }
        public static void Save_FTPConnection(string server, string username, string password)
        {
            cls_CONCryptography cls_CONCryptography = new cls_CONCryptography();

            RegistryKey _keyReg = Registry.CurrentUser.CreateSubKey(_path);
            _keyReg.SetValue("FTPServer", cls_CONCryptography.mtd_Encrypt(server));
            _keyReg.SetValue("FTPUsername", cls_CONCryptography.mtd_Encrypt(username));
            _keyReg.SetValue("FTPPassword", cls_CONCryptography.mtd_Encrypt(password));
        }
        public static FTPInfo Get_FTPConnection()
        {
            cls_CONCryptography cls_CONCryptography = new cls_CONCryptography();

            RegistryKey _keyReg = Registry.CurrentUser.CreateSubKey(_path);
            FTPInfo FTPInfo = new FTPInfo();
            FTPInfo.Server = _keyReg.GetValue("FTPServer") == null ? "" : cls_CONCryptography.mtd_Decrypt(_keyReg.GetValue("FTPServer").ToString());
            FTPInfo.Username = _keyReg.GetValue("FTPUsername") == null ? "" : cls_CONCryptography.mtd_Decrypt(_keyReg.GetValue("FTPUsername").ToString());
            FTPInfo.Password = _keyReg.GetValue("FTPPassword") == null ? "" : cls_CONCryptography.mtd_Decrypt(_keyReg.GetValue("FTPPassword").ToString());
            return FTPInfo;
        }
        public static void Save_AllowUsers(string str)
        {
            RegistryKey _keyReg = Registry.CurrentUser.CreateSubKey(_path);
            _keyReg.SetValue("AllowUsers", str);
        }
        public static string Get_AllowUsers()
        {
            RegistryKey _keyReg = Registry.CurrentUser.CreateSubKey(_path);
            return _keyReg.GetValue("AllowUsers") == null ? "" : _keyReg.GetValue("AllowUsers").ToString();
        }
	}
}
